<?php

	function isLoggedIn()
	{
			$CI = &get_instance();
			//check login
			if ($CI->session->userdata('userId') != '') return true;
			else  return false;
	}

	function loginRequired($page = '')
	{
			$CI = &get_instance();
			//check login
			if ($CI->session->userdata('userId') == '')
			{
					$CI->session->set_userdata(array('redirectURL' => $CI->uri->uri_string()));
					redirect((trim($page) == '') ? 'home' : trim($page));
			}
	}

	function doLogin($page = '')
	{
			$CI = &get_instance();
			//Login success
			if ($CI->session->userdata('redirectURL') != '') redirect($CI->session->userdata('redirectURL'));
			else  redirect((trim($page) == '') ? 'profile' : trim($page));
	}

	function loggedInTakeIn($page = '')
	{
			$CI = &get_instance();
			//check login
			if ($CI->session->userdata('userId') != '')
			{
					redirect((trim($page) == '') ? 'profile' : trim($page));
			}
	}


function getAvatar($userId, $ext)
{
		if(@$ext == '')
		{
			$userAvatar = base_url() . 'application/images/default_avatar_thumb.png';
		}
		else
		{
			$userAvatar = base_url() . 'application/userdata/profile_' . $userId . '/avatars/thumbs/' . $ext;
		}
		//$userAvatar = base_url() . 'application/userdata/profile_' . $userId . '/avatars/thumbs/' . $ext;
		//$filename = APPPATH . 'userdata/profile_' . $userId . '/avatars/thumbs/' . $ext;
		//if (!file_exists($filename)) $userAvatar = base_url() . 'application/images/default_avatar_thumb.jpg';
		return $userAvatar;
}

?>